import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["logo", "message", "style", "activityConfig", "backgroundImageUrl", "title", "subTitle", "actions", "children"];
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useIntl } from '@ant-design/pro-provider';
import { ConfigProvider } from 'antd-v4';
import { useContext, useMemo } from 'react';
import { ProForm } from '../ProForm';
import './index.less';
export function LoginFormPage(props) {
  var logo = props.logo,
      message = props.message,
      style = props.style,
      _props$activityConfig = props.activityConfig,
      activityConfig = _props$activityConfig === void 0 ? {} : _props$activityConfig,
      backgroundImageUrl = props.backgroundImageUrl,
      title = props.title,
      subTitle = props.subTitle,
      actions = props.actions,
      children = props.children,
      proFormProps = _objectWithoutProperties(props, _excluded);

  var intl = useIntl();

  var genSubmitButtonProps = function genSubmitButtonProps() {
    var _proFormProps$submitt, _proFormProps$submitt2;

    if (proFormProps.submitter === false) return false;
    if (((_proFormProps$submitt = proFormProps.submitter) === null || _proFormProps$submitt === void 0 ? void 0 : _proFormProps$submitt.submitButtonProps) === false) return false;
    return _objectSpread({
      size: 'large',
      style: {
        width: '100%'
      }
    }, (_proFormProps$submitt2 = proFormProps.submitter) === null || _proFormProps$submitt2 === void 0 ? void 0 : _proFormProps$submitt2.submitButtonProps);
  };

  var submitter = _objectSpread(_objectSpread({
    searchConfig: {
      submitText: intl.getMessage('loginForm.submitText', '登录')
    },
    render: function render(_, dom) {
      return dom.pop();
    }
  }, proFormProps.submitter), {}, {
    submitButtonProps: genSubmitButtonProps()
  });

  var context = useContext(ConfigProvider.ConfigContext);
  var baseClassName = context.getPrefixCls('pro-form-login-page');

  var getCls = function getCls(className) {
    return "".concat(baseClassName, "-").concat(className);
  };
  /** 生成logo 的dom，如果是string 设置为图片 如果是个 dom 就原样保留 */


  var logoDom = useMemo(function () {
    if (!logo) return null;

    if (typeof logo === 'string') {
      return _jsx("img", {
        src: logo
      });
    }

    return logo;
  }, [logo]);
  return _jsxs("div", {
    className: baseClassName,
    style: _objectSpread(_objectSpread({}, style), {}, {
      backgroundImage: "url(\"".concat(backgroundImageUrl, "\")")
    }),
    children: [_jsx("div", {
      className: getCls('notice'),
      children: activityConfig && _jsxs("div", {
        className: getCls('notice-activity'),
        style: activityConfig.style,
        children: [activityConfig.title && _jsxs("div", {
          className: getCls('notice-activity-title'),
          children: [" ", activityConfig.title, " "]
        }), activityConfig.subTitle && _jsxs("div", {
          className: getCls('notice-activity-subTitle'),
          children: [" ", activityConfig.subTitle, " "]
        }), activityConfig.action && _jsxs("div", {
          className: getCls('notice-activity-action'),
          children: [" ", activityConfig.action, " "]
        })]
      })
    }), _jsxs("div", {
      className: getCls('container'),
      children: [_jsxs("div", {
        className: getCls('top'),
        children: [title || logoDom ? _jsxs("div", {
          className: getCls('header'),
          children: [logoDom ? _jsx("span", {
            className: getCls('logo'),
            children: logoDom
          }) : null, title ? _jsx("span", {
            className: getCls('title'),
            children: title
          }) : null]
        }) : null, subTitle ? _jsx("div", {
          className: getCls('desc'),
          children: subTitle
        }) : null]
      }), _jsxs("div", {
        className: getCls('main'),
        children: [_jsxs(ProForm, _objectSpread(_objectSpread({
          isKeyPressSubmit: true
        }, proFormProps), {}, {
          submitter: submitter,
          children: [message, children]
        })), actions ? _jsx("div", {
          className: getCls('other'),
          children: actions
        }) : null]
      })]
    })]
  });
}